﻿var LODOP; //声明为全局变量 
var tr = true;
function prn1_print(str) {
    if (CreateOneFormPage(str)) {
        if (tr == true)
            LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Full-Page");
    }
    LODOP.PRINT();
};
function CreateOneFormPage(str) {
    try {
        LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));
        var strBodyStyle = "<style>.w{ width:95%;height:100%;border:0px;}td{padding: 0px;	margin: 0px;	text-align: left;	border: 1px solid #000000;	border-collapse: collapse;" +
		"	border-spacing: 0px;} table{	padding: 0px;	margin: 0px;	border: 1px solid #000000;	border-collapse: collapse;	border-spacing: 0px;	}</style>";
        var strFormHtml = strBodyStyle + "<body leftmargin=0 topmargin=0>" + document.getElementById(str).innerHTML + "</body>";
        if (LODOP != null) {
            LODOP.PRINT_INIT("表单");
            LODOP.SET_PRINT_STYLE("FontSize", 13);
            LODOP.ADD_PRINT_TEXT(5, "40%", 260, 6, document.getElementsByTagName('TITLE')[0].innerText);
            LODOP.ADD_PRINT_HTM(30, 0, "100%", "100%", strFormHtml);
            return true;
        }
    } catch (exexpation) { }
    return false;
};
function prn1_preview(str) {
    if (CreateOneFormPage(str)) {
        LODOP.PREVIEW();
        tr = false;
    }
};
function prn1_printA(str) {
    if (CreateOneFormPage(str))
        LODOP.PRINTA();
};
function SaveAsFile(s) {
    try {
        LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));
        LODOP.PRINT_INIT("");
        var ary = document.getElementsByTagName("td");
        var str = document.getElementById(s).innerHTML;
        var aryList = new Array();
        for (i = 0; i < ary.length; i++) {
            if (ary[i] != null && ary[i].firstChild != null)
        {
            if (ary[i].firstChild.className == 'w') {
                str = str.replace(ary[i].innerHTML, ary[i].firstChild.value.toString());
            }
            else if (ary[i].firstChild.type == "checkbox" && !ary[i].firstChild.checked) {
                str = str.replace(ary[i].innerHTML, "");
            }
             else if (ary[i].firstChild.className == "select") {
             for(var ii=0;ii<ary[i].firstChild.length;ii++)
             {
             if(ary[i].firstChild[ii].selected == true) str = str.replace(ary[i].innerHTML, ary[i].firstChild[ii].innerText=="请选择"?"":ary[i].firstChild[ii].innerText);
             }
            }
            else if (ary[i].className == "r" && (ary[i].firstChild.checked == false || ary[i].firstChild.checked==undefined)) {
            str = str.replace(ary[i].innerHTML, "");
            }
            }
        }
        LODOP.ADD_PRINT_TABLE("0%", "0%", "100%", "100%", str);
        LODOP.SAVE_TO_FILE("报表.xls");
    } catch (exexpation) { }
};

//按比例打印
function prn_preview1() {
    CreateOnePage();
    LODOP.SET_PREVIEW_WINDOW(1, 0, 0, 0, 0, "");
    LODOP.PREVIEW();
};
function prn_preview2() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Full-Width");
    LODOP.PREVIEW();
};
function prn_preview3() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Full-Height");
    LODOP.PREVIEW();
};
function prn_preview4() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Full-Page");
    LODOP.PREVIEW();
};
function prn_preview5() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Auto-Width");
    LODOP.PREVIEW();
};
function prn_preview6() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Auto-Height");
    LODOP.PREVIEW();
};
function prn_preview7() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Width:200%");
    LODOP.PREVIEW();
};
function prn_preview8() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Height:200%");
    LODOP.PREVIEW();
};
function prn_preview9() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Width:200%;Height:200%");
    LODOP.PREVIEW();
};
function prn_preview10() {
    CreateOnePage();
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "55%");
    LODOP.PREVIEW();
};
function prn_preview11() {
    CreateOnePage();
    LODOP.SET_SHOW_MODE("HIDE_PAGE_PERCENT", true);
    LODOP.SET_PREVIEW_WINDOW(1, 0, 0, 0, 0, "");
    LODOP.PREVIEW();
};
function CreateOnePage() {
    LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));
    LODOP.PRINT_INIT("表单");
    LODOP.ADD_PRINT_HTM(5, 5, "100%", "100%", "<body leftmargin=0 topmargin=0>" + document.getElementById('pri').innerHTML + "</body>");
    LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
};
